package org.wdcode.core.concurrent;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import org.wdcode.core.factory.BaseFactory;
import org.wdcode.core.params.WdCoreParams;

/**
 * ScheduledExecutor JDK新任务实现 的工厂
 * @author WD
 * @since JDK6
 * @version 1.0 2010-01-26
 */
public final class ScheduledExecutorFactory extends BaseFactory<ScheduledExecutorService> {
	// 工厂
	private final static ScheduledExecutorFactory	FACTORY;

	/**
	 * 静态初始化
	 */
	static {
		FACTORY = new ScheduledExecutorFactory();
	}

	/**
	 * 返回工厂
	 * @return 工厂
	 */
	public final static ScheduledExecutorFactory getFactory() {
		return FACTORY;
	}

	/**
	 * 新生成一个线程池
	 * @return ScheduledExecutorService
	 */
	public ScheduledExecutorService newInstance() {
		return newInstance(WdCoreParams.getThreadSize());
	}

	/**
	 * 新生成一个线程池
	 * @param size 线程个数
	 * @return ScheduledExecutorService
	 */
	public ScheduledExecutorService newInstance(int size) {
		return Executors.newScheduledThreadPool(size);
	}

	/**
	 * 私有构造
	 */
	private ScheduledExecutorFactory() {}
}
